package com.hulk.ratel.manage.commoncache;

import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.hulk.ratel.common.constant.enums.YesOrNo;
import com.hulk.ratel.persistence.entity.DictInfo;
import com.hulk.ratel.persistence.repository.IDictInfoRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import lombok.NonNull;


/**
 * Created by cmt on 2018/08/03.
 * 字典信息cache
 */
@Slf4j
@Component
public class DictInfoCache {

    @Autowired
    private IDictInfoRepository dictInfoRepository;

    //@Cacheable(value = "dictInfoCache", key = "#ruleCode+ 'DictInfoCache_findDictInfo'")
    @Cached(key = "#code + 'DictInfoCache_findDictInfo'", cacheType = CacheType.LOCAL , expire =600)
    public DictInfo findDictInfo(@NonNull String code) {
        DictInfo diParam = new DictInfo();
        diParam.setDictEn(code);
        diParam.setDictFlag(YesOrNo.YES.getValue());
        Wrapper<DictInfo> queryDictInfo = new QueryWrapper<>(diParam);
        return dictInfoRepository.getOne(queryDictInfo);
    }
}
